package com.cn.bean.pojo.file;

import java.text.DecimalFormat;

public class FileSizeFormatter {
    public static String formatSize(long size) {
        String[] units = {"B", "KB", "MB", "GB", "TB"};
        int unitIndex = 0;

        while (size > 1024 && unitIndex < units.length - 1) {
            size /= 1024;
            unitIndex++;
        }

        return new DecimalFormat("#,##0.#").format(size) + " " + units[unitIndex];
    }
}
